-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NT-330] Set initial amount from Backing #863
Conversation
private func amountFromBacking(_ backing: Backing?) -> Double? { | ||
guard let amount = backing?.amount else { return nil } | ||
|
||
return amount - Double(backing?.shippingAmount ?? 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's usually better when doing arithmetic using money types to use Decimal
:
let shippingAmount: Double = backing?.shippingAmount ?? 0
let pledgeAmount = Decimal(amount) - Decimal(shippingAmount)
return (pledgeAmount as NSDecimalNumber).doubleValue
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah good point - although we seem to have been a little inconsistent with this π€¦ββ
https://github.com/kickstarter/ios-oss/blob/master/Library/ViewModels/BackingViewModel.swift#L176
But I'll change that here!
KsApi/models/BackingTests.swift
Outdated
let backing = Backing.template | ||
|> Backing.lens.reward .~ Reward.postcards | ||
|> Backing.lens.rewardId .~ Reward.postcards.id | ||
|> Backing.lens.shippingAmount .~ 116 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really chose some easier numbers here for better understanding of what's going on in here π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π’ π’ π’
π’ π’ π’
π’ π’ π’
π² What
Follow-up to #858, this sets the initial pledge amount to that of the
Backing
if it is set in theProject
'sPersonalization
.β Acceptance criteria